package android.xml;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.model.BankItemDialogue;

/*
 * komentarite se isti kako i za BankHandler.java
 * ja vrsi iztata funkcija, no za xml dokument so razlicni tagovi
 */

public class BankHandlerDialogue extends ItemsHandler<BankItemDialogue> {
	
	
	public static final String SENTENCES = "sentences";
	public static final String SENTENCE = "sentence";
	public static final String PRONOUNCE = "pronounce";

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		
		sb.append(ch,start,length);
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		
		  if (SENTENCE.equals(currentElement)) {
			currentItem.setSentence(sb.toString().trim());
		} else if (PRONOUNCE.equals(currentElement)) {
			currentItem.setPronounce(sb.toString().trim());
		}
		currentElement = null;
		 
		
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		
		currentElement = localName;
		sb = new StringBuffer();
		if (SENTENCES.equals(currentElement)) {
			currentItem = new BankItemDialogue();
			items.add(currentItem);
		}
	}

}